package com.gmzg.gmzgnews.topic.adapters;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;

import com.gmzg.gmzgnews.R;
import com.gmzg.gmzgnews.topic.model.Food;
import com.gmzg.gmzgnews.topic.model.News;
import com.gmzg.gmzgnews.topic.model.NewsParent;
import com.squareup.picasso.Picasso;

import java.util.Collection;
import java.util.List;

/**
 * Created by liuyi_s on 2016/11/1 23:33.
 * Email：liuyi_s@foxmail.com
 */

public class TopicFollowAdapter extends RecyclerView.Adapter<TopicFollowAdapter.ViewHolder>{

    private Context mContext;
    private List<Food> mNewsList;

    public TopicFollowAdapter(Context context, List<Food> newsList) {
        mContext = context;
        mNewsList = newsList;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(
                R.layout.item_topic_follow,
                parent,
                false
        );

        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        Food foods = mNewsList.get(position);
        Picasso.with(mContext)
                .load("http://tnfs.tngou.net/img" + foods.getImgUrl())
                .into(holder.mImageViewIcon);
        holder.mTextViewTitle.setText(foods.getName());
    }

    @Override
    public int getItemCount() {
        return mNewsList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder{
        private final ImageView mImageViewIcon;
        private final TextView mTextViewTitle;
        public ViewHolder(View itemView) {
            super(itemView);
            mImageViewIcon = ((ImageView) itemView.findViewById(R.id.item_topic_follow_img));
            mTextViewTitle = ((TextView) itemView.findViewById(R.id.item_topic_follow_title));
        }


    }

    public void addAll(Collection<? extends Food> collection){
        mNewsList.addAll(collection);
        notifyDataSetChanged();
    }
}
